package com.wolfsea.viewpager2demo.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.wolfsea.viewpager2demo.databinding.Viewpage2ItemBinding

/**
 *@desc  VP2Adapter
 *@author liuliheng
 *@time 2022/3/20  19:11
 **/
class ViewPage2Adapter(context: Context) : RecyclerView.Adapter<ViewPage2Adapter.VP2ViewHolder>() {

    private val mContext = context

    var dataSet: MutableList<Int> = mutableListOf()
         set(value) {
             field = value
             notifyDataSetChanged()
         }

    private lateinit var binding: Viewpage2ItemBinding

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VP2ViewHolder {
        binding = Viewpage2ItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return VP2ViewHolder(binding.root)
    }

    override fun onBindViewHolder(holder: VP2ViewHolder, position: Int) {
        binding.ivViewPage2.background = mContext.resources.getDrawable(dataSet[position])
    }

    override fun getItemCount(): Int = dataSet.size

    class VP2ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}